package com.lanou.moving.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.lanou.moving.R;
import com.lanou.moving.entity.MusicInfo;

import java.util.List;

/**
 * Created by 刘琪 on 15/11/4.
 * 播放列表
 */
public class MusicListAdapter extends BaseAdapter {
    private List<MusicInfo> musicInfoList;
    private MusicInfo musicInfo;

    public MusicListAdapter(List<MusicInfo> musicInfoList) {
        this.musicInfoList = musicInfoList;
    }

    @Override
    public int getCount() {
        return musicInfoList != null && musicInfoList.size() > 0 ? musicInfoList.size() : 0;
    }

    @Override
    public MusicInfo getItem(int position) {
        return musicInfoList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.music_list_item, null);
            holder = new ViewHolder();
            holder.music_list_item_position = (TextView) convertView.findViewById(R.id.music_list_item_position);
            holder.music_list_item_songName = (TextView) convertView.findViewById(R.id.music_list_item_songName);
            holder.music_list_item_singerName = (TextView) convertView.findViewById(R.id.music_list_item_singerName);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        musicInfo = getItem(position);
        if (musicInfo != null) {
            holder.music_list_item_position.setText(position + 1 + "");
            holder.music_list_item_songName.setText(musicInfo.getSongName());
            holder.music_list_item_singerName.setText(musicInfo.getSingerName());
        }
        return convertView;
    }

    private class ViewHolder {
        private TextView music_list_item_position;
        private TextView music_list_item_songName;
        private TextView music_list_item_singerName;
    }
}
